/******************************************************************************
 * Copyright (C) 2015  671643387@qq.com
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 *****************************************************************************/

#ifndef LOG_LOGGER_H_
#define LOG_LOGGER_H_

#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif

#include <cstdarg>
#include <string>
#include "node/node.h"

namespace node {
    namespace log {
        class LogSystem;

        class Logger
        {
        public:
            enum SeverityLevel
            {
                SL_DEBUG = 0,
                SL_LOG,
                SL_INFO,
                SL_WARNING,
                SL_ERROR
            };

            bool initialize(void);
            void uninitialize(void);

            void debug(const char *format, ...);
            void log(const char *format, ...);
            void info(const char *format, ...);
            void warning(const char *format, ...);
            void error(const char *format, ...);

            int severity_level(void) const { return severity_level_; }
            void set_severity_level(int level) { severity_level_ = level; }
            void set_output_console(bool to_colsole) { output_console_ = to_colsole; }

        private:
            friend class LogSystem;

            Logger(const char *dir, const char *name);
            ~Logger(void);

			void outputConsole(const char *message, SeverityLevel severity_level);
            void printMessage(const char *format, ::std::va_list args, SeverityLevel severity_level);

            int id_;
            ::std::string name_;
            ::std::string directory_;
            int severity_level_;
            bool output_console_;
            DISALLOW_COPY_AND_ASSIGN(Logger);
        };

    }
}

#endif // LOG_LOGGER_H_
